package wxshop.service.admin.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import wxshop.api.admin.dao.AdminDao;
import wxshop.api.admin.exception.NameExist;
import wxshop.api.admin.exception.NameNotExist;
import wxshop.api.admin.exception.PasswordWrong;
import wxshop.api.admin.model.Admin;
import wxshop.api.admin.model.FormResult;
import wxshop.api.admin.service.AdminService;
/**
 * Created by 121874694@qq.com on 2018/3/1.
 */

@SuppressWarnings({"SpringJavaAutowiringInspection", "SpringJavaInjectionPointsAutowiringInspection"})
@Service
public class AdminServiceImpl implements AdminService {
	@Autowired
	private AdminDao adminDao;
	@Override
	public FormResult register (Admin admin) {
		if(adminDao.checkName(admin)!=null){
			throw new NameExist();
		}
		return new FormResult(true);
	}
	
	@Override
	public FormResult login (Admin admin) {
		Admin a = adminDao.FindPasswordByName(admin);
		if(a==null){
			throw new NameNotExist();
		}
		if(!admin.getPassword().equals(a.getPassword())){
			throw new PasswordWrong();
		}

		return new FormResult(true,a.getId());
	}
}
